
var advertisingArr = []
chrome.storage.local.get("slideshowUrl")

    .then(async res => {

        let Imgurl = [];
        let clickUrl = [];
        res.slideshowUrl.forEach(item => {
            if (item.includes("img")) {
                Imgurl.push(item)
            } else {
                clickUrl.push(item)
            }
        });


        for (let i = 0; i < Imgurl.length; i++) {
            let data = {
                "url": Imgurl[i],
                "page": Imgurl[i]
            }

            advertisingArr.push(data)
        }


        for (let i = 0; i < advertisingArr.length; i++) {
            document.querySelector(".swiper-wrapper").innerHTML += `<img class="swiperblock" data-click="${advertisingArr[i].page}" src="${advertisingArr[i].url}" alt="">`

            document.querySelector(".swiper-pagination").innerHTML += `<div class="selectTab"><span></span></div>`

        }

        let swiper = document.querySelectorAll(".swiper-wrapper>img")

        var swiperindex = 0;

        setInterval(() => {
            if (swiperindex == 5) {
                swiperindex = 0;
            }
            for (let i = 0; i < swiper.length; i++) {
                swiper[i].classList.remove("swiperblock")
            }
            swiper[swiperindex].classList.add("swiperblock")

            for (let j = 0; j < document.querySelectorAll(".swiper-pagination>div").length; j++) {
                document.querySelectorAll(".swiper-pagination>div")[j].classList.remove("selectTab")
            }
            document.querySelectorAll(".swiper-pagination>div")[swiperindex].classList.add("selectTab")


            swiperindex++
        }, 1000);



        for (let i = 0; i < swiper.length; i++) {
            swiper[i].onclick = function () {
                console.log(swiper[i])
                console.log(swiper[i].getAttribute("data-click"))
                window.open(swiper[i].getAttribute("data-click"), '_blank');
            }
        }

        let swiperPagination = document.querySelectorAll(".swiper-pagination>div")
        for (let i = 0; i < swiperPagination.length; i++) {
            swiperPagination[i].onclick = function () {
                // console.log(swiperPagination[i])
                swiperindex = i
            }
        }
        console.log(advertisingArr)

    })







